﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using MedicService.Domain;
using MedicService.Server.Factory.Generic;

namespace MedicService.Server.Factory {
    public class SettingsFactory : EntityFactory<Settings> {
        public SettingsFactory() : base("Settings") { }
        protected override Settings CreateEntity() {
            return new Settings();
        }

        protected override string GetInsertQuery(Settings entity) {
            String q = "INSERT INTO [Settings] ([AlertTime],[NextNumber]) VALUES (" + Nullable(entity.AlertTime) + "," + Nullable(entity.NextNumber) + ")";
            return q;
        }

        protected override string GetUpdateQuery(Settings entity) {
            String q = "UPDATE [Settings] SET [AlertTime] = "+Nullable(entity.AlertTime)
                + ", [NextNumber] = " + Nullable(entity.NextNumber)
                +" WHERE id="+entity.Id;
            return q;
        }

        protected override void FillEntity(Settings entity, DataRow myDataRow) {
            base.FillEntity(entity, myDataRow);
            entity.AlertTime = int.Parse("" + myDataRow["AlertTime"]);
            string s = "" + myDataRow["NextNumber"];
            if (!string.IsNullOrEmpty(s)) {
                entity.NextNumber = int.Parse(s);
            } else {
                entity.NextNumber = 0;
            }
        }
    }
}